//
//  CALayer+YSExtension.h
//  YSKitExample
//
//  Created by Kyson on 2017/6/16.
//  Copyright © 2017年 YangShen. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

NS_ASSUME_NONNULL_BEGIN

@interface CALayer (YSExtension)

- (nullable UIImage *)ys_snapshotImage;

- (nullable NSData *)ys_snapshotPDF;

/**
 *  设置阴影
 *
 *  @param color  阴影颜色
 *  @param offset 阴影偏移
 *  @param radius 阴影半径(程度，越大越黑)
 */
- (void)ys_setLayerShadow:(UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius;

/**
 *  删除所有子Layer
 */
- (void)ys_removeAllSublayers;

#pragma mark - property
@property (nonatomic) CGFloat ys_left;      ///< frame.origin.x
@property (nonatomic) CGFloat ys_top;       ///< frame.origin.y
@property (nonatomic) CGFloat ys_right;     ///< frame.origin.x + frame.size.width
@property (nonatomic) CGFloat ys_bottom;    ///< frame.origin.x + frame.size.height
@property (nonatomic) CGFloat ys_width;     ///< frame.size.width
@property (nonatomic) CGFloat ys_height;    ///< frame.size.height
@property (nonatomic) CGPoint ys_center;       ///< center
@property (nonatomic) CGFloat ys_centerX;   ///< center.x
@property (nonatomic) CGFloat ys_centerY;   ///< center.y
@property (nonatomic) CGPoint ys_origin;    ///< frame.origin
@property (nonatomic) CGSize  ys_size;       ///< frame.size

@property (nonatomic) CGFloat ys_transformRotation;     ///< key path "tranform.rotation"
@property (nonatomic) CGFloat ys_transformRotationX;    ///< key path "tranform.rotation.x"
@property (nonatomic) CGFloat ys_transformRotationY;    ///< key path "tranform.rotation.y"
@property (nonatomic) CGFloat ys_transformRotationZ;    ///< key path "tranform.rotation.z"
@property (nonatomic) CGFloat ys_transformScale;        ///< key path "tranform.scale"
@property (nonatomic) CGFloat ys_transformScaleX;       ///< key path "tranform.scale.x"
@property (nonatomic) CGFloat ys_transformScaleY;       ///< key path "tranform.scale.y"
@property (nonatomic) CGFloat ys_transformScaleZ;       ///< key path "tranform.scale.z"
@property (nonatomic) CGFloat ys_transformTranslationX; ///< key path "tranform.translation.x"
@property (nonatomic) CGFloat ys_transformTranslationY; ///< key path "tranform.translation.y"
@property (nonatomic) CGFloat ys_transformTranslationZ; ///< key path "tranform.translation.z"

/**
 Shortcut for transform.m34, -1/1000 is a good value.
 It should be set before other transform shortcut.
 */
@property (nonatomic) CGFloat ys_transformDepth;

/**
 Add a fade animation to layer's contents when the contents is changed.
 
 @param duration Animation duration
 @param curve    Animation curve.
 */
- (void)ys_addFadeAnimationWithDuration:(NSTimeInterval)duration curve:(UIViewAnimationCurve)curve;

/**
 Cancel fade animation which is added with "-addFadeAnimationWithDuration:curve:".
 */
- (void)ys_removePreviousFadeAnimation;

@end

@interface CALayer (ys_Transition)

/** 动画类型 */
typedef NS_ENUM(NSInteger, TransitionAnimType) {
    //水波
    TransitionAnimTypeRippleEffect = 0,
    
    //吸走
    TransitionAnimTypeSuckEffect,
    
    //翻开书本
    TransitionAnimTypePageCurl,
    
    //正反翻转
    TransitionAnimTypeOglFlip,
    
    //正方体
    TransitionAnimTypeCube,
    
    //push推开
    TransitionAnimTypeReveal,
    
    //合上书本
    TransitionAnimTypePageUnCurl,
    
    //镜头开
    TransitionAnimTypeCameraIrisHollowOpen,
    
    //镜头关
    TransitionAnimTypeCameraIrisHollowClose,
    
    //随机
    TransitionAnimTypeRamdom,
};

/** 动画类型2-方向 */
typedef NS_ENUM(NSInteger, TransitionSubType) {
    //从上
    TransitionSubtypesFromTop = 0,
    
    //从左
    TransitionSubtypesFromLeft,
    
    //从下
    TransitionSubtypesFromBotoom,
    
    //从右
    TransitionSubtypesFromRight,
    
    //随机
    TransitionSubtypesFromRamdom,
};


/** 动画曲线 */
typedef NS_ENUM(NSInteger, TransitionCurve) {
    //默认
    TransitionCurveDefault = 0,
    
    //缓进
    TransitionCurveEaseIn,
    
    //缓出
    TransitionCurveEaseOut,
    
    //缓进缓出
    TransitionCurveEaseInEaseOut,
    
    //线性
    TransitionCurveLinear,
    
    //随机
    TransitionCurveRamdom,
};

/**
 *  转场动画
 *
 *  @param animType 转场动画类型
 *  @param subType  转动动画方向
 *  @param curve    转动动画曲线
 *  @param duration 转动动画时长
 *
 *  @return 转场动画实例
 */
- (CATransition *)ys_transitionWithAnimType:(TransitionAnimType)animType
                                    subType:(TransitionSubType)subType
                                      curve:(TransitionCurve)curve
                                   duration:(CGFloat)duration;

@end
NS_ASSUME_NONNULL_END
